﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Image2d
{
    class Asteroids:AnimatedObject2D
    {
        float velocity;
        Vector2 direction;

        Vector2 clientBounds;

        public Asteroids(Texture2D image, Vector2 position, Animation[] animations,
            float rotation, float velocity, Vector2 bounds)
            : base(image, position, animations)
        {
            this.Rotation = rotation;
            this.velocity = velocity;
            Origin = new Vector2(Rect.Width / 2, Rect.Height / 2);
            direction = new Vector2((float)Math.Sin(rotation), -(float)Math.Cos(rotation));
            clientBounds = bounds;
        }

/**/    public bool CheckUpdate(GameTime gameTime)
        {
           
            Rect = currentAnimation.UpdateRect(Rect, gameTime);
            Position += direction * velocity;
            return CheckBounds();
           
        }

/**/    public bool CheckBounds()
        {
            //se ele sair esquerda vai para direita
            if (Position.X < 0 - this.currentAnimation.frameSize.X / 2)
            {
                return true;
            }
            //se ele sair esquerda vai para direita
            else if (Position.X > clientBounds.X + this.currentAnimation.frameSize.X / 2)
            {
                return true;
            }
            //cima vai para baixo
            else if (Position.Y < 0 - this.currentAnimation.frameSize.Y / 2)
            {
                return true;
            }
            //baixo vai para cima
            else if (Position.Y > clientBounds.Y + this.currentAnimation.frameSize.Y / 2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



    }
}
